<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>企业员工工资管理-工资项列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="static/css/font.css">
  <link rel="stylesheet" href="static/css/xadmin.css">
  <script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
  <script type="text/javascript" src="static/lib/layui/layui.js"></script>
  <script type="text/javascript" src="static/js/xadmin.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
  <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
  <!--<![endif]&ndash;&gt;-->

</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a >首页</a>
        <a >工资项管理</a>
        <a>
          <cite>工资项</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body layui-anim layui-anim-up">
  <form class="layui-form" action="">
  <input type="hidden" name="id" id="wage-id" />
    <div class="x-body" id="container">
      <div class="demoTable">
        迟到罚金：
        <div class="layui-inline">
          <input class="layui-input" name="late_buckle_payTxt" id="late_buckle_payTxt" lay-verify="late_buckle_payTxtVerify" autocomplete="off">
        </div>
        元/次
      </div>
      <br>
      <div class="demoTable">
        早退罚金：
        <div class="layui-inline">
          <input class="layui-input" name="early_buckle_payTxt" id="early_buckle_payTxt" lay-verify="early_buckle_payTxtVerify" autocomplete="off">
        </div>
        元/次
      </div>
      <br>
      <div class="demoTable">
        出差补贴：
        <div class="layui-inline">
          <input class="layui-input" name="missionallowanceTxt" id="missionallowanceTxt" lay-verify="missionallowanceTxtVerify" autocomplete="off">
        </div>
        元/天
      </div>
      <br>
      <div class="demoTable">
        全勤奖金：
        <div class="layui-inline">
          <input class="layui-input" name="full_attendance_payTxt" id="full_attendance_payTxt" lay-verify="full_attendance_payTxtVerify" autocomplete="off">
        </div>
        元/月
      </div>
      <br>
      <div class="demoTable">
        餐饮补贴：
        <div class="layui-inline">
          <input class="layui-input" name="food_payTxt" id="food_payTxt" lay-verify="food_ payTxtVerify" autocomplete="off">
        </div>
        元/月
      </div>
      <br>
      <div class="demoTable">
        交通补贴：
        <div class="layui-inline">
          <input class="layui-input" name="traffic_payTxt" id="traffic_payTxt" lay-verify="traffic_payTxtVerify" autocomplete="off">
        </div>
        元/月
      </div>
      <br>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit="" lay-filter="wage-form-btn">保存</button>
        </div>
      </div>
     
    </div>
  </form>
</div>

<script>
    window.onload = function () {
        $.ajax({
        	url:'getAllWageItem.do',
        	type:'POST',
        	data:'',
        	success:function(result){
        		if(result.type=="success"){
        			var data=result.data;
        			if(data.length>0){
        				$("#late_buckle_payTxt").val(data[2].kvValue);
            			$("#early_buckle_payTxt").val(data[3].kvValue);
            			$("#missionallowanceTxt").val(data[4].kvValue);
            			$("#full_attendance_payTxt").val(data[5].kvValue);
            			$("#food_payTxt").val(data[0].kvValue);
            			$("#traffic_payTxt").val(data[1].kvValue);
            			$("#wage-id").val(1);
        			}
        			
        		}
        	},
        	error:function(error){
        		alert("网络错误")
        	}
        })
    }
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //自定义验证规则
        form.verify({
            late_buckle_payTxtVerify: function(value){

                var number=new RegExp("^(0|[1-9][0-9]*|-[1-9][0-9]*)$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '迟到罚金不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '迟到罚金只能是整数';
                }
            },
            early_buckle_payTxtVerify: function(value){

                var number=new RegExp("^(0|[1-9][0-9]*|-[1-9][0-9]*)$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '早退罚金不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '早退罚金只能是整数';
                }
            },
            missionallowanceTxtVerify: function(value){

                var number=new RegExp("^[0-9]*$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '出差补贴不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '出差补贴只能是非负整数';
                }
            },
            full_attendance_payTxtVerify: function(value){

                var number=new RegExp("^[0-9]*$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '全勤奖金不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '全勤奖金只能是非负整数';
                }
            },
            food_payTxtVerify: function(value){

                var number=new RegExp("^[0-9]*$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '餐饮补贴不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '餐饮补贴只能是非负整数';
                }
            },
            traffic_payTxtVerify: function(value){

                var number=new RegExp("^[0-9]*$");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '交通补贴不能为空';
                }
                if(value.length > 10){
                    return '输入金额过长';
                }
                if(!number.test(value)){
                    return '交通补贴只能是非负整数';
                }
            },


        });


        // 监听提交
        form.on('submit(wage-form-btn)', function(data){
            //发异步，把数据提交
            $.ajax({
                type: 'post',
                url: 'changeWageItem.do',
                data: {
                	'id':$("#wage-id").val(),
                    'late_buckle_pay': $("#late_buckle_payTxt").val(),
                    'early_buckle_pay': $("#early_buckle_payTxt").val(),
                    'missionallowance': $("#missionallowanceTxt").val(),
                    'full_attendance_pay': $("#full_attendance_payTxt").val(),
                    'food_pay': $("#food_payTxt").val(),
                    'traffic_pay': $("#traffic_payTxt").val(),
                },
                success: function (result) {
                	if(result.code==100){
                		 layer.alert("保存成功", {icon: 6});
                	}else{
                		layer.msg('保存失败!',{icon: 5,anim: 6});	
                	}  
                },
                error: function (err) {
                    alert("网络错误");
                }

            });
            return false;
        });
    });

</script>

</body>

</html>